package com.atguigu.yygh.controller.api;

import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.result.Result;
import com.atguigu.yygh.service.DepartmentService;
import com.atguigu.yygh.service.HospitalService;
import com.atguigu.yygh.service.HospitalSetService;
import com.atguigu.yygh.service.ScheduleService;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.atguigu.yygh.vo.hosp.ScheduleOrderVo;
import com.atguigu.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author zr
 * @date 2021/12/15 19:32
 */
@Api(tags = "医院API接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospApiController {
    @Resource
    private HospitalService hospitalService;
    @Resource
    private DepartmentService departmentService;
    @Resource
    private ScheduleService scheduleService;
    @Resource
    private HospitalSetService hospitalSetService;
    @ApiOperation("查询医院列表")
    @GetMapping("findHospList/{page}/{limit}")
    public Result findHospList(@ApiParam(name = "page", value = "当前页码", required = true)
                               @PathVariable Integer page,
                               @ApiParam(name = "limit", value = "每页记录数", required = true)
                               @PathVariable Integer limit,
                               @ApiParam(name = "hospitalQueryVo", value = "查询对象", required = false)
                                       HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitalPage = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitalPage);
    }

    @ApiOperation("根据医院名称查询")
    @GetMapping("findByHosName/{hosName}")
    public Result findByHosName(@PathVariable String hosName) {
        List<Hospital> hospitalList = hospitalService.findByHosName(hosName);
        return Result.ok(hospitalList);
    }

    @ApiOperation("根据医院编号获取科室列表")
    @GetMapping("department/{hosCode}")
    public Result departmentList(@PathVariable String hosCode) {
        List<DepartmentVo> departmentVos = departmentService.findDeptTree(hosCode);
        return Result.ok(departmentVos);
    }

    @ApiOperation(value = "医院预约挂号详情")
    @GetMapping("departmentDetail/{hosCode}")
    public Result getDepartDetail(@PathVariable String hosCode) {
        Map<String, Object> resultMap = hospitalService.getDepartDetail(hosCode);
        return Result.ok(resultMap);
    }

    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hosCode}/{depCode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hosCode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depCode) {
        Map<String, Object> resultMap = scheduleService.getBookingScheduleRule(page, limit, hosCode, depCode);
        return Result.ok(resultMap);
    }

    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate) {
        List<Schedule> scheduleDetail = scheduleService.getScheduleDetail(hoscode, depcode, workDate);
        return Result.ok(scheduleDetail);
    }

    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(@ApiParam(name = "scheduleId", value = "排班id", required = true)
                              @PathVariable String scheduleId) {
        Schedule schedule = scheduleService.getSchedule(scheduleId);
        return Result.ok(schedule);
    }

    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    @ApiOperation(value = "获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable("hoscode") String hoscode) {
        return hospitalSetService.getSignInfoVo(hoscode);
    }
}
